import java.util.*;
public class OrderingSystem {
    static String[] names=new String[10];
    static String[] disMeg=new String[10];
    static int[] times=new int[10];
    static String[] address=new String[10];
    static int[] states=new int[10];//保存订单状态：0表示已预订；1表示已完成
    static double[] sumPrices=new double[10];
    static double[] prices=new double[4];
    static String dishNames[]=new String[4];
    static int praiseNums[]=new int[4];

    public static void main(String[] args) {
        names[0]="张三";
        disMeg[0]="红烧带鱼2份";
        times[0]=12;
        address[0]="巢湖路207号";
        sumPrices[0]=76.0;
        states[0]=1;
        names[1]="李四";
        disMeg[1]="鱼香肉丝2份";
        times[1]=14;
        address[1]="芜湖路207号";
        sumPrices[1]=45.0;
        states[1]=0;
        dishNames[0]="红烧带鱼";
        prices[0]=38.0;
        praiseNums[0]=3;
        dishNames[1]="鱼香肉丝";
        prices[1]=20.0;
        praiseNums[1]=2;
        dishNames[2]="时令鲜蔬";
        prices[2]=10.0;
        praiseNums[2]=1;
        dishNames[3]="小龙虾";
        prices[3]=60.0;
        praiseNums[3]=10;
        Scanner input = new Scanner(System.in);
        int num = -1; // 用户输入0返回主菜单，否则退出系统
        boolean isExit = false; // 标志用户是否退出系统： true:退出系统

        System.out.println("\n欢迎使用“吃货联盟订餐系统”");
        // 循环：显示菜单，根据用户选择的数字执行相应功能
        do {
            // 显示菜单
            System.out.println("****************************");
            System.out.println("1、我要订餐");
            System.out.println("2、查看餐袋");
            System.out.println("3、签收订单");
            System.out.println("4、删除订单");
            System.out.println("5、我要点赞");
            System.out.println("6、退出系统");
            System.out.println("****************************");
            System.out.print("请选择：");
            int choose = input.nextInt(); // 记录用户选择的功能编号
            boolean isAdd = false;  //记录是否可以订餐
            boolean isSignFind = false;  //找到要签收的订单
            boolean isDelFind = false;  //找到要删除的订单
            // 根据用户选择的功能编号执行相应功能
            switch (choose) {
                case 1:
                    // 我要订餐
                    System.out.println("***我要订餐***");
                    reservationTable();
                    break;
                case 2:
                    // 查看餐袋
                    System.out.println("***查看餐袋***");
                    myMealBag();
                    break;
                case 3:
                    // 签收定单
                    System.out.println("***签收定单***");
                    singFor();
                    break;
                case 4:
                    System.out.println("***删除定单***");
                    delete();
                    break;
                case 5:
                    // 我要点赞
                    System.out.println("***我要点赞***");
                    praise();
                    break;
                case 6:
                    // 退出系统
                    isExit = true;
                    break;
                default:
                    //退出系统
                    isExit = true;
                    break;
            } //end switch
            if (isExit == false) {
                System.out.print("输入0返回：");
                num = input.nextInt();
            } else {
                break; //退出循环
            }
        } while (num == 0);
        System.out.println("谢谢使用，欢迎下次光临！");
    }
    public  static void reservationTable(){
        Scanner input = new Scanner(System.in);
        boolean isAdd=false;
        for (int i = 0; i <names.length ; i++) {
            if(names[i]==null){
                isAdd=true;
                System.out.print("请输入订餐人姓名:");
                String name=input.next();
                System.out.println("序号\t菜名\t单价\t点赞数");
                for(int j=0;j<dishNames.length;j++) {
                    String price=prices[j]+"元";
                    String praiseNum=(praiseNums[j]>0)?praiseNums[j]
                            +"赞":"0";
                    System.out.println((j+1)+"\t"+dishNames[j]+"\t"
                            +price+"\t"+praiseNum);
                }
                System.out.print("请选择你要输入的菜品编号:");
                int chooseDish=input.nextInt();
                System.out.print("请选择你需要的份数:");
                int number=input.nextInt();
                String dishMeg=dishNames[chooseDish-1]+""+number+"份";
                double sumPrice=prices[chooseDish-1]*number;
                double deliCharge=(sumPrice>50)?0:5;
                System.out.print("请输入送餐时间(送餐时间是10点至20点间整点送餐):");
                int time=input.nextInt();
                if(time<10||time>20) {
                    System.out.println("您的输入有误，请输入10~20之间的整数!");
                    time=input.nextInt();
                }
                System.out.print("请输入送餐地址:");
                String address1=input.next();
                System.out.println("订餐成功!");
                System.out.println("您订的是:"+dishMeg);
                System.out.println("送餐时间:"+time+"点");
                System.out.println("送餐地址是:"+address1);
                System.out.println("餐费:"+sumPrice+"元,送餐费"+deliCharge
                        +"元,总计:"+(sumPrice+deliCharge)+"元.");
                names[i]=name;
                disMeg[i]=dishMeg;
                times[i]=time;
                address[i]=address1;
                sumPrices[i]=sumPrice;
                break;
            }
        }
    }
    public static  void myMealBag(){
        System.out.println("序号\t订餐人\t餐品信息\t\t送餐时间\t送餐地址"
                + "\t\t总金额\t订单状态");
        for(int i=0;i<names.length;i++) {
            if(names[i]!=null) {
                String state=(states[i]==0)?"已预订":"已完成";
                String date=times[i]+"点";
                String sumPrice=sumPrices[i]+"元";
                System.out.println((i+1)+"\t"+names[i]
                        +"\t\t"+disMeg[i]+"\t"+date+"\t\t"
                        +address[i] +"\t"+sumPrice+"\t"+state);
            }
        }
    }
    public static  void  singFor(){
        Scanner input=new Scanner(System.in);
        boolean isSignFind=false;
        System.out.print("请输入你要签收的订单号:");
        int signOrderld=input.nextInt();
        if(names[signOrderld-1]!=null&&states[signOrderld-1]==0){
            System.out.println("签收成功!");
            states[signOrderld-1]=1;
            isSignFind=true;
        }else if (names[signOrderld-1]!=null&&states[signOrderld-1]==1){
            System.out.println("您选择的订单已签收,不能再次签收!");
            isSignFind=true;
        }
        if(!isSignFind) {
            System.out.println("您选择的订单号不存在!");
        }
    }
    public static void delete(){
        Scanner input=new Scanner(System.in);
        boolean isDelFind=false;
        System.out.print("请输入要删除的订单号:");
        int delId=input.nextInt();
        if(names[delId-1]!=null&&states[delId-1]==1){
            isDelFind=true;
            for (int i = 0; i < names.length-1; i++) {
                names[i]=names[i+1];
                disMeg[i]=disMeg[i+1];
                times[i]=times[i+1];
                address[i]=address[i+1];
                states[i]=states[i+1];
                sumPrices[i]=sumPrices[i+1];
            }
            int endIndex=names.length-1;
            names[endIndex]=null;
            disMeg[endIndex]=null;
            times[endIndex]=0;
            address[endIndex]=null;
            states[endIndex]=0;
            sumPrices[endIndex]=0;
            System.out.println("删除订单成功!");

        }else if (names[delId-1]!=null&&states[delId-1]==0){
            System.out.println("您选择的订单号未签收，不能删除！");
            isDelFind=true;
        }
    }
    public static  void  praise(){
        Scanner input=new Scanner(System.in);
        System.out.println("序号"+"\t"+"菜名"+"\t\t"+"单价");
        for(int i=0;i<dishNames.length;i++) {
            String price=prices[i]+"元";
            String praiseNum=(praiseNums[i])>0?praiseNums[i]+"赞":"";
            System.out.println((i+1)+"\t"+dishNames[i]+"\t"
                    +price+"\t"+praiseNum);
        }
        System.out.print("请选择您要点赞的菜品序号:");
        int praiseNum=input.nextInt();
        praiseNums[praiseNum-1]++;
        System.out.println("点赞成功!");
    }

}
